package com.itheima.demoString;

public class Demo02String {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = "ab";
        //变量 + 常量 相当于一次new,指向堆空间
        String s3 = s2 + "c";
        System.out.println(s1 == s3);

        String s4 = "c";
        //变量 + 变量 相当于一次new,指向堆空间
        String s5 = s2 + s4;
        System.out.println(s1 == s5);

        //常量优化机制,指向字符串常量池
        String s6 = "a" + "b" + "c";
        System.out.println(s1 == s6);
    }
}
